<template>
  <div style="width: 100%; height: 100%;">
      <el-upload
      class="upload-demo"
      action="/api/onnx/process"
      :show-file-list="false"
      >
      <el-button size="small" type="primary">图片上传</el-button>
    </el-upload>
    <el-table :data="tableData" border style="width: 100%;margin-top: 20px;">
      <el-table-column prop="fileName" label="图片名称"></el-table-column>
      <el-table-column prop="input" label="原始图片">
        <template slot-scope="scope">
           <!-- 图片显示
           如果 type 为 input则显示 
           -->

            <img
              :src="scope.row.input"
              style="width: 100px; height: 100px"
              alt=""
            />
        </template>
      </el-table-column>
      <el-table-column prop="output" label="标注图片">
        <template slot-scope="scope">
           <!-- 图片显示
           如果 type 为 input则显示 
           -->

            <img
              :src="scope.row.output"
              style="width: 100px; height: 100px"
              alt=""
            />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getPictureList } from "@/api/picture";
export default {
  name: "HomeView",
  data() {
    return {
      tableData: [],
      tableData2: [],
    };
  },
  mounted() {
    this.getPictureList();
  },
  methods: {
    getPictureList() {
      getPictureList().then(res => {
        const rawData = res.data;

  // 按 fileName 分组合并
  const groupedData = rawData.reduce((acc, item) => {
    const key = item.fileName;
    if (!acc[key]) {
      acc[key] = {};
    }
    if (item.type === 'input') {
      acc[key].input = "/api/onnx/image/" + item.fileName;
    } else if (item.type === 'output') {
      acc[key].output = "/api/onnx/aimage/" + item.fileName;
    }
    acc[key].fileName = item.fileName;
    return acc;
  }, {});

  console.log(groupedData);
  
  // 转换为数组格式供表格使用
  this.tableData = Object.values(groupedData);
      });
    }
  }
};
</script>

<style scoped>
.el-table .cell {
  white-space: normal;
}
</style>